{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "output_type": "stream",
     "name": "stdout",
     "text": [
      "**BinanceNeutralStrategy_2**\n",
      "\n",
      "**前次持仓**: \n",
      "QTUMUSDT: 29.8\n",
      "IOSTUSDT: -4457.0\n",
      "ZRXUSDT: 69.0\n",
      "OMGUSDT: 10.3\n",
      "SNXUSDT: -2.3\n",
      "FTMUSDT: -1728.0\n",
      "GRTUSDT: 67.0\n",
      "\n",
      "下次执行时间: 2021-01-24 15:00:00\n",
      "trade_usdt_old： 50 trade_usdt_new： 50 \n",
      "\n",
      "**账户净值**: 50 USDT\n",
      "\n",
      "     key  策略分配资金_旧  策略分配资金_新\n",
      "0  3h_0H  4.166667  4.166667\n",
      "1  3h_1H  4.166667  4.166667\n",
      "2  3h_2H  4.166667  4.166667\n",
      "AKRO/USDT 数据太少\n",
      "DOTECO/USDT 数据太少\n",
      "CHZ/USDT 数据太少\n",
      "获取所有币种K线数据完成，花费时间： 1.1555159091949463 80\n",
      "Empty DataFrame\n",
      "Columns: [key, s_time, symbol, 方向, 策略分配资金_旧, 策略分配资金_新, 策略分配资金, 目标下单量]\n",
      "Index: [] \n",
      "\n",
      "**本次仓位更新**: \n",
      "ZRXUSDT: -69.0\n",
      "GRTUSDT: -67.0\n",
      "QTUMUSDT: -29.8\n",
      "OMGUSDT: -10.3\n",
      "SNXUSDT: 2.3\n",
      "FTMUSDT: 1728.0\n",
      "IOSTUSDT: 4457.0\n",
      "\n",
      "\n",
      " -------------------- 本次循环结束，10.000000秒后进入下一次循环 -------------------- \n",
      "\n",
      "\n"
     ]
    },
    {
     "output_type": "error",
     "ename": "KeyboardInterrupt",
     "evalue": "",
     "traceback": [
      "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[0;31mKeyboardInterrupt\u001b[0m                         Traceback (most recent call last)",
      "\u001b[0;32m<ipython-input-1-5ba5d7d72a72>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m\u001b[0m\n\u001b[1;32m     13\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m     14\u001b[0m \u001b[0mneu\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mBinanceSwapNeutral\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mbc_cfg\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m''\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mLogType\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mBINANCE_NEUTRAL\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;32mTrue\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m---> 15\u001b[0;31m \u001b[0mneu\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mperform_proc\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m",
      "\u001b[0;32m~/Staff/Repo/CYGatro/CYProcedure/cy_procedure/subject/neutral/proc/binance_swap_neutral.py\u001b[0m in \u001b[0;36mperform_proc\u001b[0;34m(self)\u001b[0m\n\u001b[1;32m    290\u001b[0m                 \u001b[0mrecorder\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mrecord_summary_log\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m    291\u001b[0m                 \u001b[0mprint\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m'\\n'\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m'-'\u001b[0m \u001b[0;34m*\u001b[0m \u001b[0;36m20\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m'本次循环结束，%f秒后进入下一次循环'\u001b[0m \u001b[0;34m%\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_long_sleep_time\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m'-'\u001b[0m \u001b[0;34m*\u001b[0m \u001b[0;36m20\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m'\\n\\n'\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 292\u001b[0;31m                 \u001b[0mtime\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0msleep\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_long_sleep_time\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m    293\u001b[0m             \u001b[0;32mexcept\u001b[0m \u001b[0mException\u001b[0m \u001b[0;32mas\u001b[0m \u001b[0m_\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m    294\u001b[0m                 \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_generate_recorder\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mrecord_exception\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mtraceback\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mformat_exc\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
      "\u001b[0;31mKeyboardInterrupt\u001b[0m: "
     ]
    }
   ],
   "source": [
    "from cy_data_access.connection.connect import *\n",
    "from cy_data_access.models.quant import *\n",
    "from cy_data_access.models.log import *\n",
    "from cy_widgets.strategy.neutral import *\n",
    "from cy_procedure.subject.neutral.proc.binance_swap_neutral import *\n",
    "\n",
    "connect_db_env(db_name=DB_QUANT)\n",
    "connect_db_env(db_name=DB_CONFIG)\n",
    "connect_db_env(db_name=DB_MARKET)\n",
    "connect_db_env(db_name=DB_POSITION)\n",
    "connect_db_env(db_name=DB_LOG)\n",
    "bc_cfg = BrickCarrierCfg.objects.get({'_id': 3})\n",
    "\n",
    "neu = BinanceSwapNeutral(bc_cfg, '', LogType.BINANCE_NEUTRAL, True)\n",
    "neu.perform_proc()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "output_type": "stream",
     "name": "stdout",
     "text": [
      "['angle', 'apz', 'atr', 'bias', 'bolling', 'bop', 'cci_ema', 'cci', 'cmo', 'cr', 'dbcd', 'dc', 'ddi', 'dema', 'force', 'gap', 'hullma', 'ko', 'ma_displaced', 'market_pnl', 'mtm_mean', 'pac', 'pmo', 'psy', 'pvt', 'rccd', 'reg', 'reg_ta', 'rsi', 'rwih', 'rwil', 'trix', 'uos', 'v1_up', 'v3', 'vidya', 'vix_bw', 'vix', 'vma', 'vwap_bias', '收高差值', '癞子', '资金流入比例']\nCount: 43\n"
     ]
    }
   ],
   "source": [
    "import cy_widgets.neutral.neutral_indicators as ids\n",
    "indicators = list(map(lambda x: x.split('_indi')[0], list(filter(lambda x: '_indicator' in x, dir(ids)))))\n",
    "print(indicators)\n",
    "print('Count:', len(indicators))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.5-final"
  },
  "orig_nbformat": 2,
  "kernelspec": {
   "name": "python3",
   "display_name": "Python 3.7.5 64-bit",
   "metadata": {
    "interpreter": {
     "hash": "80ee594ed1f0f8fa52ab02efb8867e8d1fe9a7efefd553c9d05a22fe95619ba4"
    }
   }
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}